<?php

    class excellib{
        
        public    $workbook;
        public    $filename;
        public    $current_file;
        public    $excelObject = null;
        
        public function __construct(){
            //error_reporting(0);
            require_once "application/libraries/phpexcel/Classes/PHPExcel.php";   
            $this->workbook = new PHPExcel();
        }
        
        public function load($file = null){
            if($file == null || !file_exists($file))return;
            $this->current_file = $file;
        }
        
        public function read($func_callback){
                    $inputFileName = $this->current_file;
                    $inputFileType = PHPExcel_IOFactory::identify($this->current_file); 
                    $objReader = PHPExcel_IOFactory::createReader($inputFileType); 
                    $objReader->setReadDataOnly(true); 
                    $this->excelObject = $objReader->load($inputFileName); 
                    
                    $objWorksheet = $this->excelObject->setActiveSheetIndex(0);
                    $highestRow = $objWorksheet->getHighestRow();
                    $highestColumn = $objWorksheet->getHighestColumn();
                    $headingsArray = $objWorksheet->rangeToArray('A3:'.$highestColumn.'3',null, true, true, true);
                    $headingsArray = $headingsArray[0];
                 
                    for($row=1;$row<=$highestRow;$row++){
                        $func_callback(
                            $objWorksheet->rangeToArray('A'  . $row . ":" . $highestColumn  . $row,null, true, true, true)
                        );
                    }
        }

        public function createheader($header){

      $this->workbook->getProperties()->setCreator("Maarten Balliauw")
							 ->setLastModifiedBy("Maarten Balliauw")
							 ->setTitle("Office 2007 XLSX Test Document")
							 ->setSubject("Office 2007 XLSX Test Document")
							 ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
							 ->setKeywords("office 2007 openxml php")
                                                            ->setCategory("Test result file");
               $this->workbook->setActiveSheetIndex(0)
                            ->setCellValue('A1', 'CustomerID ภาษาไทย')
                            ->setCellValue('B1', 'Name')
                            ->setCellValue('C1', 'Email')
                             ->setCellValue('D1', 'CountryCode')
                            ->setCellValue('E1', 'Budget')
                            ->setCellValue('F1', 'Used');
               $this->workbook->setActiveSheetIndex(0)
               ->setCellValue('F10', 'ทดสอบการออกรายงานน่ะจ๊ะ');
                $this->workbook->getActiveSheet()->setTitle('My Customer');
                $objWriter   = PHPExcel_IOFactory::createWriter($this->workbook, 'Excel2007');
                $strFileName = "myData.xlsx";
                $objWriter->save($strFileName);
        }
        
        
    }
?>